from django.db import models


class BaseModel(models.Model):
  '''公共模型'''
  orders = models.IntegerField(default=1, verbose_name='排序')
  is_show = models.BooleanField(default=False, verbose_name='是否显示')
  is_deleted = models.BooleanField(default=False, verbose_name='是否删除')
  created = models.DateTimeField(auto_now_add=True, verbose_name='添加时间', null=True, blank=True)
  updated = models.DateTimeField(auto_now=True, verbose_name='更新时间', null=True, blank=True)

  class Meta:
    abstract = True


class Banner(BaseModel):
  '''轮播图模型'''
  title = models.CharField(max_length=500, verbose_name='广告标题')
  link = models.CharField(max_length=500, verbose_name='广告链接')
  image = models.ImageField(upload_to='banners', verbose_name='图片')
  remark = models.TextField(verbose_name='备注信息')

  class Meta:
    db_table = 'ly_banner'
    verbose_name = '轮播广告'
    verbose_name_plural = verbose_name

  def __str__(self):
    return self.title


class Nav(BaseModel):
  '''导航菜单模型'''
  POSITION_OPTION = (
    (1, "顶部导航"),
    (2, "底部导航"),
  )
  title = models.CharField(max_length=500, verbose_name='导航标题')
  link = models.CharField(max_length=500, verbose_name='导航链接')
  position = models.IntegerField(choices=POSITION_OPTION, default=1, verbose_name='导航位置')
  is_site = models.BooleanField(default=False, verbose_name='是否站外地址')

  class Meta:
    db_table = 'ly_nav'
    verbose_name = '导航'
    verbose_name_plural = verbose_name

  def __str__(self):
    return self.title
